{% extends "base.html" %}

{% block title %}管理员管理 - 学生成绩管理系统{% endblock %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/common.css') }}">
{% block content %}
<div class="admins-wrapper">

    <!-- 页面标题和操作按钮 -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2 class="page-title">
                <i class="fas fa-book text-primary"></i>
                管理员管理
            </h2>   
            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addAdminModal">
                <i class="fas fa-plus"></i> 添加管理员    
            </button>
        </div>

            <!-- 搜索和筛选区域 -->
        <div class="card mb-4">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-2">
                        <div class="input-group">
                            <span class="input-group-text"><i class="fas fa-search"></i></span>
                            <input type="text" class="form-control" id="searchInput" placeholder="搜索管理员名称...">
                        </div>
                    </div>
                    <div class="col-md-1">
                        <button type="button" class="btn btn-outline-secondary w-100" onclick="resetFilters()">
                            <i class="fas fa-redo"></i> 重置
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 列表 -->
    <div class="card">
        <div class="card-header">
            <h5 class="card-title mb-0">
                <i class="fas fa-list"></i> 管理员列表
                <span class="badge bg-primary ms-2" id="listCount">0</span>
            </h5>
        </div>
        <div class="card-body">
            <!-- 加载状态 -->
            <div id="loadingSpinner" class="text-center py-4">
                <div class="spinner-border text-primary" role="status">
                    <span class="visually-hidden">加载中...</span>
                </div>
                <p class="mt-2 text-muted">正在加载管理员数据...</p>
            </div>

            <!-- 管理员表格 -->
            <div class="table-responsive" id="adminTableContainer" style="display: none;">
                <table class="table table-hover" id="adminTable">
                    <thead class="table-light">
                        <tr>
                            <th>管理员ID</th>
                            <th>管理员名称</th>
                            <th>角色</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="adminTableBody">
                        <!-- 管理员数据 -->
                    </tbody>
                </table>
            </div>

            <!-- 空状态 -->
            <div id="emptyState" class="text-center py-5" style="display: none;">
                <i class="fas fa-book fa-3x text-muted mb-3"></i>
                <h5 class="text-muted">暂无管理员数据</h5>
                <p class="text-muted">点击上方"添加管理员"按钮开始添加管理员</p>
            </div>

        </div>
    </div>

    <!-- 分页 -->
    <div aria-label="管理员分页" class="mt-4">
        <ul class="pagination justify-content-center" id="pagination">
            <!-- 分页按钮 -->
        </ul>
    </div>
</div>

    <!-- 添加模态框 -->
<div class="modal fade" id="addAdminModal" tabindex="-1" aria-labelledby="addAdminModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="addAdminModalLabel">
                    <i class="fas fa-plus text-primary"></i> 添加管理员
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form id="addAdminForm">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="addAdminUsername" class="form-label">用户名 <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="addAdminUsername" name="username" required>
                                <div class="invalid-feedback">请输入用户名</div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="addCoursePassword" class="form-label">密码 <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="addCoursePassword" name="password" required>
                                <div class="invalid-feedback">请输入密码</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-save"></i> 保存
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>


<!-- 编辑模态框 -->
<div class="modal fade" id="editAdminModal" tabindex="-1" aria-labelledby="editAdminModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="editAdminModalLabel">
                    <i class="fas fa-edit text-warning"></i> 编辑管理员
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form id="editAdminForm">
                <div class="modal-body">
                    <input type="hidden" id="editAdminId" name="id">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="editAdminUsername" class="form-label">用户名 <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="editAdminUsername" name="username" required>
                                <div class="invalid-feedback">请输入用户名</div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="editAdminPassword" class="form-label">密码 <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="editAdminPassword" name="password" required>
                                <div class="invalid-feedback">请输入密码</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-warning">
                        <i class="fas fa-save"></i> 更新
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>


<!-- 删除模态框 -->
<div class="modal fade" id="deleteAdminModal" tabindex="-1" aria-labelledby="deleteAdminModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="deleteAdminModalLabel">
                    <i class="fas fa-exclamation-triangle text-danger"></i> 确认删除
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <p>您确定要删除管理员 <strong id="deleteAdminInfo"></strong> 吗？</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <button type="button" class="btn btn-danger" id="confirmDeleteBtn">
                    <i class="fas fa-trash"></i> 确认删除
                </button>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='js/admin/admin.js') }}"></script>
{% endblock %}